<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ page import="entities.Utente"%>
<%@ page import= "java.util.Date"%>
<%@ page import= "java.text.SimpleDateFormat"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Modifica Profilo</title>

<script language=javascript type="text/javascript">
function validazioneModulo(pswdModulo) {
	if (pswdModulo.password.value == "") {
		alert ("Attenzione!!! Hai dimenticato di inserire la password!")
		pswdModulo.password.focus()
		return false
	}
	if (pswdModulo.password.value != pswdModulo.passwordConfirm.value) {
		alert ("Attenzione!!! Errore nella conferma password!")
		pswdModulo.password.focus()
		pswdModulo.passwordConfirm.select()
		return false
	}
	return true
}
</script>

<link rel="stylesheet" type="text/css" href="/ProgettoWeb/Style/style.css" />
</head>
<body>

	

	<script type="text/javascript" src="/ProgettoWeb/js/jquery.js"></script>
	<script type="text/javascript">
	$(document).ready(function(){
		$('#header').load('/ProgettoWeb/Common/header.jsp');
		$('#menu').load('/ProgettoWeb/Common/menu.jsp');
		$('#onFooter').load('/ProgettoWeb/Common/onFooter.jsp');
		$('#footer').load('/ProgettoWeb/Common/footer.jsp');
	});
	</script>
	<div id="header"></div>
	<div id="menu"></div>
	<%String state;
	state = (String) session.getAttribute("state");
	if(state!=null && state.length()>0){
		if(state.equals("error")){
		%>Si e' verificato un errore!
	<%	}
		//non c'e' stato alcun errore
		if(state.equals("modifyData")){
			%>I tuoi dati sono stati modificati correttamente!
	<%	}			
		if(state.equals("modifyPassword")){
			%>La tua password e' stata cambiata!
	<%	}
		if(state.equals("mailError")){
			%>La mail scelta e' gia' usata da qualcuno! cambiala!
	<%	}
		if(state.equals("errorOldPassword")){
			%>La password vecchia non e' corretta!
	<%	}
	}
	
	Utente user = (Utente) session.getAttribute("user");
	if(user!=null){
	
		String utilDate = null;
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy/MM/dd");
		utilDate = formatter.format(user.getDataNascita());
		%>
	<table border="0" cellpadding="1" cellspacing="2" width="100%">
	<tr>
	<td align="left">
	
	<form name="Modifica" action="/ProgettoWeb/ModificaServlet?modify=all" method="POST">

		<table border="0" cellpadding="1" cellspacing="2" width="100%">

			<TBODY>

				<tr>
					<td align="left" width="0%">nome:</td>
					<td align="left" width="100%"><INPUT id="nome"
						name="nome" value="<%=user.getNome()%>"></td>
				</tr>

				<tr>
					<td align="left" width="0%">cognome:</td>
					<td align="left" width="100%"><INPUT id="cognome"
						name="cognome" value="<%=user.getCognome()%>"></td>
				</tr>

				<tr>
					<td align="left" width="0%">email:</td>
					<td align="left" width="100%"><INPUT id="email"
						name="email" value="<%=user.getEmail()%>"></td>
				</tr>
								
				<tr>
					<td align="left" width="0%">data:</td>
					<td align="left" width="100%"><INPUT id="data"
						name="data" value="<%=utilDate%>"></td>
				</tr>
				
				<tr>
					<td align="left" width="0%">numCel:</td>
					<td align="left" width="100%"><INPUT id="numCel"
						name="numCel" value="<%=user.getNumCellulare()%>"></td>
				</tr>

				<tr>
					<td align="left" width="0%">numTel:</td>
					<td align="left" width="100%"><INPUT id="numTel"
						name="numTel" value="<%=user.getNumTelefono()%>"></td>
				</tr>
	
				<tr>
					<td align="left" width="0%"></td>
					<td align="left" width="50%"><input type="submit"
						value="Modifica"></td>
				</tr>

			</TBODY>

		</table>

		<br> <br>
	</form>
	
	</td>
	<td align="right">
	<form name="ModifyPassword" action="/ProgettoWeb/ModificaServlet?modify=password" method="POST" onSubmit="return validazioneModulo(this)">

		<table border="0" cellpadding="1" cellspacing="2" width="100%">
			<TBODY>
			
				<tr>
					<td align="right" width="0%">Inserisci la vecchia password</td>
					<td align="right" width="50%"><input type="password" name ="oldPassword"
						value=""></td>
				</tr>
				
				<tr>
					<td align="right" width="0%">Inserisci la nuova password</td>
					<td align="right" width="50%"><input type="password" name ="password"
						value=""></td>
				</tr>
				<tr>
					<td align="right" width="0%">Conferma la nuova password</td>
					<td align="right" width="50%"><input type="password" name ="passwordConfirm"
						value=""></td>
				</tr>
				<tr>
					<td align="right" width="0%"></td>
					<td align="right" width="50%"><input type="submit"
						value="cambia password"></td>
				</tr>
			</TBODY>
		</table>
	</form>
	
	</td>
	</tr>
	</table>
	<%} %>
	<%session.removeAttribute("state");
	session.removeAttribute("user");%>
	
	<div id="onFooter"></div>
	<div id="footer"></div>
</body>
</html>